<template>
    <div style="width: 100%;height: 100vh; overflow: hidden;padding: 15px; box-sizing: border-box;">
        <!-- 页面标题 -->
        <header style="text-align: center;">
            <h1>
                工地上工账本
            </h1>
            <p style="line-height: 1.5rem;">
                管理工地每日用工计划，同步统计工时、核算工资、记录考勤，实现用工信息规范化管理。
            </p>
        </header>

        <ul class="list">
            <li v-for="(item, index) in dataList" :key="index" @click="goAtPresent(item)">
                {{ item.bookName }}
            </li>
        </ul>

        <button class="btn" @click="addBook">添加账本</button>


        <el-dialog title="新增账单" :visible.sync="open" width="90%">
            <p style="line-height: 2rem;"><span style="font-weight: 700;">账单名称: </span> (打个比方: 这本账单你想要记那个方向的账 , 如果是工地的话,
                可以输入工地名称, 如果是家庭支出的话,
                可以输入家庭支出之类的话)</p>

            <el-input style="margin: 15px 0;" v-model="bookName" placeholder="请输入"></el-input>

            <el-button class="save" @click="save">保存</el-button>
        </el-dialog>
    </div>
</template>

<script>
import { addConstructionSiteBill, getConstructionSiteBill } from '@/api/getConstructionSiteBill';

export default {
    data() {
        return {
            open: false,
            bookName: '',
            dataList: []
        };
    },

    methods: {
        async getInit() {
            let result = await getConstructionSiteBill({ page: 1, size: 10000 });
            if (result.code == 20000) {
                this.dataList = result.data
            }
        },


        addBook() {
            this.open = true;
        },

        goAtPresent(item) {
            this.$router.push(`/constructionSiteBillDetail?id=${item.id}`)
        },

        async save() {
            if (!this.bookName) {
                this.$message.warning('请输入书名');
                return
            }

            let result = await addConstructionSiteBill({
                bookName: this.bookName,
                salary: 300,
                morning: 3,
                afternoon: 5
            })

            if (result.code == 20000) {
                this.getInit()
                this.open = false
            }
        }
    },

    mounted() {
        this.getInit()
    }
};
</script>

<style scoped lang="scss">
* {
    margin: 0;
    padding: 0;
}

.list {
    width: 100%;
    amx-height: 75vh;
    display: flex;
    justify-content: space-between;
    margin-top: 15px;
    flex-wrap: wrap;
    overflow-y: auto;

    li {
        flex: 0 0 49%;
        width: 49%;
        height: 154px;
        border-radius: 10px;
        list-style: none;
        background-image: url('../../assets/image/book.png');
        background-size: 70%;
        background-position: center;
        background-repeat: no-repeat;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-weight: 700;
        padding: 0 50px 0 60px;
        box-sizing: border-box;
        margin-bottom: 15px;
        // 文字溢出换行
        // white-space: nowrap;
    }
}

.btn {
    width: 98%;
    margin: 0 auto;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background-color: #2B9C4A;
    color: #fff;
    font-weight: 700;
    border-radius: 10px;
    font-size: 18px;
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

.save {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: 15px auto 0;
    height: 40px;
    background-color: #2B9C4A;
    border-radius: 10px;
    color: #fff;

}
</style>